//
//  XcodeCleanVM.swift
//  ZJTools
//
//  Created by 万孟超 on 2023/11/17.
//

import AppKit

class XcodeCleanVM {
    
    var itemChangeBlock: (Int) -> ()
    
    init(itemChangeBlock: @escaping (Int) -> Void) {
        self.itemChangeBlock = itemChangeBlock
    }
    
    var currentIndex = 0
    
    lazy var itemArray: [XcodeCleanItemM] = {
        
        var home = XcodeCleanItemM(title: "分析") {[weak self] in
            guard let self = self else { return }
            if self.currentIndex != 0 {
                self.itemChangeBlock(0)
                self.currentIndex = 0
            }
        }
        
        var derivedData = XcodeCleanItemM(title: XcodeCleanManager.CleanModelType.currentTitle(0)) {[weak self] in
            guard let self = self else { return }
            if self.currentIndex != 1 {
                self.itemChangeBlock(1)
                self.currentIndex = 1
            }
        }
        
        var cache = XcodeCleanItemM(title: XcodeCleanManager.CleanModelType.currentTitle(1)) {[weak self] in
            guard let self = self else { return }
            if self.currentIndex != 2 {
                self.itemChangeBlock(2)
                self.currentIndex = 2
            }
        }
        
        var archive = XcodeCleanItemM(title: XcodeCleanManager.CleanModelType.currentTitle(2)) {[weak self] in
            guard let self = self else { return }
            if self.currentIndex != 3 {
                self.itemChangeBlock(3)
                self.currentIndex = 3
            }
        }
        
        var deviceSupport = XcodeCleanItemM(title: XcodeCleanManager.CleanModelType.currentTitle(3)) {[weak self] in
            guard let self = self else { return }
            if self.currentIndex != 4 {
                self.itemChangeBlock(4)
                self.currentIndex = 4
            }
        }
        
        var simulator = XcodeCleanItemM(title: XcodeCleanManager.CleanModelType.currentTitle(4)) {[weak self] in
            guard let self = self else { return }
            if self.currentIndex != 5 {
                self.itemChangeBlock(5)
                self.currentIndex = 5
            }
        }
        
       return [home, derivedData, cache, archive, deviceSupport, simulator]
    }()
}
